local cijue = fk.CreateSkill {
  name = "inker_cijue",
  tags = { Skill.Compulsory }
}

cijue:addEffect(fk.CardUseFinished, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(cijue.name) and data.card and data.card.is_damage_card
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local use_event = room.logic:getCurrentEvent()
    local red_count = 0
    room.logic:getEventsByRule(GameEvent.MoveCards, 1, function(e)
      for _, move in ipairs(e.data) do
        if move.toArea == Card.Processing then
          for _, info in ipairs(move.moveInfo) do
            local c = Fk:getCardById(info.cardId)
            if c.color == Card.Red then
              red_count = red_count + 1
            end
          end
        end
      end
    end, use_event.id)
    if red_count == 0 then return false end
    local cards = room:askToCards(player, {
      min_num = red_count,
      max_num = red_count,
      pattern = ".|.|.|hand",
      skill_name = cijue.name,
      prompt = "#inker_cijue-invoke:::" .. red_count,
    })
    event:setCostData(self, { cards = cards, number = red_count, history_branch = #cards > 0 and "recast" or "draw" })
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local dat = event:getCostData(self)
    if dat.history_branch == "recast" then
      room:recastCard(dat.cards, player, cijue.name)
    else
      player:drawCards(dat.number, cijue.name)
      room:invalidateSkill(player, cijue.name, "-turn", cijue.name)
    end
  end,
})

Fk:loadTranslationTable{
  ["inker_cijue"] = "辞绝",
  [":inker_cijue"] = "锁定技，当你使用伤害牌后，重铸X张手牌，或摸X张牌令此技能本回合失效（X为结算中进入处理区的红色牌数）。",

  ["#inker_cijue-invoke"] = "辞绝：你需重铸 %arg 张手牌，或摸 %arg 张牌令此技能本回合失效",

  ["$inker_cijue1"] = "承君之恩，今日尽报。",
  ["$inker_cijue2"] = "下次沙场相见，关某定不留情。",
}

return cijue